<%@page import="dao.UserManager"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Virtual Intranet Library - Registration</title>
</head>
<body>
<jsp:useBean id="user" class="model.User" scope="request"/>
<%
	if(request.getParameter("submit") != null){
		
%>
<jsp:setProperty name="user" property="*" />
<%
		if(user.validate(true)){
			UserManager.registerUser(user);
			session.setAttribute("user", user);
			response.sendRedirect("home.jsp");
		}
	}
%>


<h2>Welcome to the registration page!</h2>
	<form method="post">
		Username: <input type="text" name="username" value="<%= user.getUsername() %>"> <%= user.getError("username") %><br>
		Password: <input type="password" name="password1"> <%= user.getError("password1") %> <br>
		Repeat password: <input type="password" name="password2"> <%= user.getError("password2") %> <br>
		Name: <input type="text" name="name" value="<%= user.getName() %>"> <%= user.getError("name") %> <br>
		Surname: <input type="text" name="surname" value="<%= user.getSurname() %>"> <%= user.getError("surname") %> <br>
		E-mail: <input type="text" name="email" value="<%= user.getEmail() %>"> <%= user.getError("email") %> <br>
		Workplace: <input type="text" name="workplace" value="<%= user.getWorkplace() %>"><br>
		<input type="submit" name="submit" value="Register">	
	</form>
	<a href="home.jsp">Back to home page</a>
</body>
</html>